from utils.logger import  log
import time


def de_get_token(func):
    """获取飞书token的装饰器"""
    log.debug("进入了装饰器：de_get_token")
    def wrapper(*args, **kwargs):
        from robot_method import get_token
        get_token()
        result = func(*args, **kwargs)
        log.debug("退出了装饰器：de_get_token")
        return result
    return wrapper

def de_log_time_exceptions(func):
    """装饰器：计时 + 日志记录 + 异常捕获"""
    def wrapper(*args, **kwargs):
        start_time = time.time()
        try:
            log.debug(f"函数 '{func.__name__}' 开始执行")
            result = func(*args, **kwargs)
            end_time = time.time()
            log.debug(f"函数 '{func.__name__}' 执行完成，耗时：{end_time - start_time:.4f} 秒")
            return result
        except Exception as e:
            log.error(f"函数 '{func.__name__}' 执行时发生异常：{e}", exc_info=True)
            raise
    return wrapper

if __name__ == '__main__':
    @de_log_time_exceptions
    def example(a,b):
        return a+b


    print(example(2,2))